from tortoise import fields
from tortoise.models import Model

#每个题目
class Questions(Model):
    # id=fields.IntField(pk=True,description='主键')
    tigan = fields.CharField(max_length=500, description='题干')
    answer = fields.CharField(max_length=500, description='答案')
    jiexi = fields.CharField(max_length=500, description='解析', null=True)
    create_time = fields.DatetimeField(auto_now_add=True, description='创建时间')
    nianji = fields.IntField(description='年级')
    kemu = fields.CharField(max_length=20, description='科目')
    leixing = fields.CharField(max_length=20, description='类型')
    laiyuan = fields.CharField(max_length=20, description='来源')
    nandu = fields.CharField(max_length=20, description='难度')
    pingjia = fields.CharField(max_length=500, description='评价', null=True)
    youhua = fields.CharField(max_length=500, description='优化建议', null=True)
    papers = fields.ForeignKeyField('models.Papers', related_name='questions', null=True)
    is_valid = fields.BooleanField(default=True, description='是否弃用，False表示弃用')
    is_low = fields.BooleanField(default=True, description='是否低质，False表示低质', null=True)
    right_time = fields.IntField(default=0, description='做对次数')
    false_time = fields.IntField(default=0, description='做错次数')


#试卷
class Papers(Model):
    name = fields.CharField(max_length=100, description='试卷名称')
    desc = fields.CharField(max_length=500, description='试卷描述')
    author = fields.CharField(max_length=100, description='创建人')
    create_time = fields.DatetimeField(auto_now_add=True, description='创建时间')
    score = fields.IntField(description='试卷总分')
    is_valid = fields.BooleanField(default=True, description='是否弃用，False表示弃用')



#试卷详情
class Paper_Detail(Model):
    paper_id = fields.ForeignKeyField('models.Papers', related_name='paper_detail')
    question_id = fields.ForeignKeyField('models.Questions', related_name='paper_detail')
    score = fields.FloatField(description='单题分数')

#考试
class Exam(Model):
    name = fields.CharField(max_length=100, description='考试名称')
    paper_id = fields.ForeignKeyField('models.Papers', related_name='exam')
    stu_id = fields.IntField(description='考生id')
    score = fields.FloatField(null=True,description='考试分数')
    create_time = fields.DatetimeField(auto_now_add=True, description='考试时间')
    wrong_questions_id = fields.CharField(null=True,max_length=500, description='错题序号列表')
    stu_search = fields.CharField(null=True,max_length=500, description='学生搜索信息')
    tea_search = fields.CharField(null=True,max_length=500, description='老师搜索信息')

#考试详情
class Exam_Detail(Model):
    exam_id = fields.ForeignKeyField('models.Exam', related_name='exam_detail')
    stu_id = fields.IntField(description='考生id')
    paper_id = fields.IntField(description='试卷id')
    question_id = fields.IntField(description='考题id')
    answer = fields.CharField(max_length=500, description='答题信息')
    is_right = fields.BooleanField(default=False,description='是否正确')
    exam_score = fields.FloatField(null=True,default=False,description='考试分数')




